﻿using BrowserCollect;
using Sy.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public class Helper
    {
        public static async Task<string> GetMerchants(string address, string keywords)
        {
            var geo = await BrowserCollector.GetHtmlAsync($"https://www.google.com/maps/place/{address}");
            var result = await BrowserCollector.GetHtmlAsync($"https://www.google.com/maps/search/{keywords}/@{geo}");
            return result;
        }

        public static string FormatCsvField(string field)
        {
            if (field == null)
                return string.Empty;

            var result = field.Trim();
            result = result.Replace("\"", "\"\""); // 替换英文冒号 英文冒号需要换成两个冒号
            if (result.Contains(",") || result.Contains("\"") || result.Contains("\r") || result.Contains("\n")) // 含逗号 冒号 换行符的需要放到引号中
            {
                result = string.Format("\"{0}\"", result);
            }
            return result;
        }
    }

}
